package com.sxm.yiwei.activitis;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.sxm.yiwei.R;
import com.sxm.yiwei.adapters.HopeStoreListAdapter;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class HomeHopeStoreActivity extends BaseActivity implements View.OnClickListener {

    private PullToRefreshListView hopestorelist;
    private ImageView hopestoreback;
    private TextView hopestoreapply;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_hope_store);
        initHopeStoreView();
        toastBegin();
        hopestorelist = (PullToRefreshListView) findViewById(R.id.hopestore_list);
        List<Integer>mList = new ArrayList<>();
        for (int i = 1; i < 15; i++) {
            mList.add(i);
        }
        HopeStoreListAdapter storeListAdapter = new HopeStoreListAdapter(HomeHopeStoreActivity.this, mList);
        hopestorelist.setAdapter(storeListAdapter);
        storeListAdapter.setListOnClick(new HopeStoreListAdapter.OnClickList() {
            @Override
            public void onListClick(int p) {
                startActivity(new Intent(HomeHopeStoreActivity.this,HopeStoreActivity.class));
            }
        });
        hopestorelist.setMode(PullToRefreshBase.Mode.BOTH);
        hopestorelist.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                Toast.makeText(HomeHopeStoreActivity.this, "下拉加载", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                Toast.makeText(HomeHopeStoreActivity.this, "上拉刷新", Toast.LENGTH_SHORT).show();
            }
        });
    }
        // 引导弹窗
    private void toastBegin() {
        AlertDialog.Builder builder = new AlertDialog.Builder(HomeHopeStoreActivity.this,R.style.NoBackGroundDialog);
        View view = LayoutInflater.from(HomeHopeStoreActivity.this).inflate(R.layout.homestore_begintoast, null);
        ImageView close = (ImageView) view.findViewById(R.id.begintoast_close);
        builder.setView(view);
        final AlertDialog dialog = builder.create();
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    private void initHopeStoreView() {

        hopestoreback = (ImageView) findViewById(R.id.hopestore_back);
        hopestoreapply = (TextView) findViewById(R.id.hopestore_apply);

        hopestoreback.setOnClickListener(this);
        hopestoreapply.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.hopestore_back:
                finish();
                break;
            case R.id.hopestore_apply:
                startActivity(new Intent(HomeHopeStoreActivity.this,ApplyHopeStoreActivity.class));
                break;
        }
    }
}
